package com.harry.drawlayout_project.base;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.FragmentActivity;

import com.harry.drawlayout_project.R;

/**
 * @author Martin-harry
 * @date 2022/1/1
 * @address
 * @Desc 基类
 */
public abstract class BaseActivity extends FragmentActivity {

    protected RelativeLayout baseLayout;
    protected TextView baseTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base);
        //初始化布局
        baseLayout = findViewById(R.id.baseLayout);
        baseLayout.addView(addContentLayout());
        baseTitle = findViewById(R.id.tv_main_title);
        //初始化控件
        initView();
        //初始化数据
        initData();
    }

    protected abstract View addContentLayout();

    protected abstract void initView();

    protected abstract void initData();

    /**
     * 设置标题
     * @param name
     */
    public void setTitle(String name){
        baseTitle.setText(name);
    }

    protected void openActivity(Class<?> cls) {
        openActivity(this, cls);
    }

    public static void openActivity(Context context, Class<?> cls) {
        Intent intent = new Intent(context, cls);
        context.startActivity(intent);
    }
}
